class canvasLibrary {
  constructor(ctx){
    this.ctx = ctx
  }
  
  //绘制圆角矩形
  drawRoundedRect({x, y, width, height, r, fill, stroke}) {
    let ctx = this.ctx;
    ctx.save(); 
    ctx.beginPath();
    ctx.moveTo(x + r, y);
    ctx.arcTo(x + width, y, x + width, y + r, r);
    ctx.arcTo(x + width, y + height, x + width - r, y + height, r);
    ctx.arcTo(x, y + height, x, y + height - r, r);
    ctx.arcTo(x, y, x + r, y, r);
    if (fill) { 
      ctx.fillStyle = fill
      ctx.fill(); 
    }
    if (stroke) { 
      ctx.strokeStyle = stroke
      ctx.stroke(); 
    }
    ctx.restore();
  }
  //绘制圆形图片
  drawRoundedImage({x,y,width,imgUrl}){
    let yd_X = x + (width/2);
    let yd_y = y + (width/2);
    this.ctx.save();
    this.ctx.beginPath();
    this.ctx.arc(yd_X,yd_y,width/2,0,2*Math.PI,false);
    this.ctx.clip();
    this.ctx.drawImage(imgUrl,x,y,width,width);
    console.log(imgUrl)
    this.ctx.restore()
  }
  //文字超出自动隐藏
  textOverflow({lineHeight, fontSize, x, y, lineClamp=1,width,text}){
    let ctx = this.ctx;
    ctx.save();
    ctx.font = ''
    const textWidth = ctx.measureText(text).width;
    
  }
}
export default canvasLibrary